package com.sky.controller.admin;

import com.sky.dto.TurnoverReportDto;
import com.sky.service.ReportService;
import com.sky.web.controller.BaseController;
import com.sky.web.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @Author tzl
 * @Date 2023/8/4 16:42  星期五
 * @ClassName ReportController
 * @Description 数据统计接口
 */
@Api(tags = "数据统计相关接口")
@Slf4j
@RestController
@RequestMapping("/admin/report")
public class ReportController extends BaseController {


    @Autowired
    private ReportService reportService;

    /**
     * 营业额统计
     * @param  dto 统计参数
     * @return
     */
    @GetMapping("/turnoverStatistics")
    @ApiOperation("营业额统计")
    public AjaxResult turnoverStatistics(TurnoverReportDto dto){
        Map<String,Object> map = reportService.getTurnoverStatistics(dto);
        return AjaxResult.success(map);
    }


    /**
     * 用户数量统计
     * @param  dto 统计参数
     * @return
     */
    @GetMapping("/userStatistics")
    @ApiOperation("用户数量统计")
    public AjaxResult userStatistics(TurnoverReportDto dto, HttpServletRequest request){
        Map<String,Object> map = reportService.getUserStatistics(dto);
        return AjaxResult.success(map);
    }

    /**
     * 订单数量统计
     * @param  dto 统计参数
     * @return
     */
    @GetMapping("/ordersStatistics")
    @ApiOperation("订单数量统计")
    public AjaxResult ordersStatistics(TurnoverReportDto dto){
        Map<String,Object> map = reportService.getOrdersStatistics(dto);
        return AjaxResult.success(map);
    }


    /**
     * 统计销量前10的商品
     * @param  dto 统计参数
     * @return
     */
    @GetMapping("/top10")
    @ApiOperation("统计销量前10的商品")
    public AjaxResult top10(TurnoverReportDto dto){
        Map<String,Object> map = reportService.getTop10(dto);
        return AjaxResult.success(map);
    }

    /**
     * 导出30天运营文件Excel
     * @param  response 返回流
     * @return
     */
    @GetMapping("/export")
    @ApiOperation("导出30天运营文件Excel")
    public void export(HttpServletResponse response){
        reportService.exportBusinessData(response);
    }
}
